*****************************************************************************************************************************************************************************************
****************************************************************************Turnout analyses*********************************************************************************************
*****************************************************************************************************************************************************************************************
cd "E:\workdata\704429\Projektfiles\Co-residence"
est clear
use analysis_out_data_all_pairs, clear

**Generate stacked datasæt**
gen id=_n
replace koen1 = koen1 - 1 
replace koen2 = koen2 - 1 

save temp_analysis1.dta, replace
foreach var in stemt residentialstability stemte_2009 pnr FOED_DAG koen  {
	rename `var'1 `var'3
	rename `var'2 `var'1
	rename `var'3 `var'2
}

append using temp_analysis1.dta

lab def koen 0 "male" 1 "female"
lab val koen1 koen
lab val koen2 koen

gen month_factor=month13+83.5  

eststo: reg stemt1 b84.month_factor  ///
if month13_factor >= 72 & month13_factor <= 96 & ///
 stemte_20091 == 1 & stemte_20092 == 1 , cluster(id) 

eststo: reg stemt1 b85.month_factor  ///
if month13_factor >= 72 & month13_factor <= 96 & ///
 stemte_20091 == 1 & stemte_20092 == 1 , cluster(id) 

eststo: reg stemt1 b84.month_factor  ///
if month13_factor >= 72 & month13_factor <= 96 & ///
 stemte_20091 == 1 & stemte_20092 == 0 , cluster(id) 

eststo: reg stemt1 b85.month_factor  ///
if month13_factor >= 72 & month13_factor <= 96 & ///
 stemte_20091 == 1 & stemte_20092 == 0 , cluster(id) 

eststo: reg stemt1 b84.month_factor  ///
if month13_factor >= 72 & month13_factor <= 96 & ///
 stemte_20091 == 0 & stemte_20092 == 1 , cluster(id) 
 
eststo: reg stemt1 b85.month_factor  ///
if month13_factor >= 72 & month13_factor <= 96 & ///
 stemte_20091 == 0 & stemte_20092 == 1 , cluster(id) 
 
eststo: reg stemt1 b84.month_factor  ///
if month13_factor >= 72 & month13_factor <= 96 & ///
 stemte_20091 == 0 & stemte_20092 == 0 , cluster(id) 

 eststo: reg stemt1 b85.month_factor  ///
if month13_factor >= 72 & month13_factor <= 96 & ///
 stemte_20091 == 0 & stemte_20092 == 0 , cluster(id) 

esttab est1 est3 est5 est7 , nostar replace ci b(3)
esttab est2 est4 est6 est8 , nostar replace ci b(3)


* Find N

log using move_in_graphs/extra.log, append
bysort stemte_20091 stemte_20092: tab month_factor if month13_factor >= 82 & month13_factor <= 85 & stemte_20091!=. & stemte_20092!=., sort // min. N Table 4
log close
